"""
Case Type   : DSS元数据修复工具
Case Name   : dsstbox基础参数验证
Create At   : 2025/04
Owner       : haomeng
Description :
    1、查看dsstbox帮助信息
    2、查看dsstbox详细帮助信息
    3、查看dsstbox版本信息
    4、查看ssrepair帮助信息
Expect      :
    1、查看成功
    2、查看成功
    3、查看成功
    4、查看成功
History     :
"""

import os
import time
import unittest

from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro


class DSSrepairtools(unittest.TestCase):

    def setUp(self):
        self.log = Logger()
        self.log.info(f'----{os.path.basename(__file__)} start----')
        self.user_node = Node('PrimaryDbUser')

        self.help_list = ['-h', '--help']
        self.all_help_list = ['-a', '--all']
        self.version_list = ['-v', '--version']
        self.ssrepair_list = ['ssrepair -h', 'ssrepair --help']
        self.info_res = []

    def test_dsstbox(self):
        text = '-----step1:查看dsstbox帮助信息;  expect:查看成功-----'
        self.log.info(text)

        for param in self.help_list:
            check_cmd = f"source {macro.DB_ENV_PATH};dsstbox {param};"
            self.log.info(check_cmd)
            check_res = self.user_node.sh(check_cmd).result()
            self.log.info(check_res)

            self.info_res.clear()

            for line in check_res.split(' '):
                self.info_res.append(line)
            self.log.info(self.info_res)
            self.assertEqual(71, len(self.info_res), '帮助信息查看失败')

        text = '-----step2:查看dsstbox详细帮助信息;  expect:查看成功-----'
        self.log.info(text)

        for param in self.all_help_list:
            check_cmd = f"source {macro.DB_ENV_PATH};dsstbox {param};"
            self.log.info(check_cmd)
            check_res = self.user_node.sh(check_cmd).result()
            self.log.info(check_res)

            self.info_res.clear()

            for line in check_res.split(' '):
                self.info_res.append(line)
            self.log.info(self.info_res)
            self.assertEqual(309, len(self.info_res), '详细帮助信息查看失败')

        text = '-----step3:查看dsstbox版本信息;  expect:查看成功-----'
        self.log.info(text)

        for param in self.version_list:
            check_cmd = f"source {macro.DB_ENV_PATH};dsstbox {param};"
            self.log.info(check_cmd)
            check_res = self.user_node.sh(check_cmd).result()
            self.log.info(check_res)
            self.assertIn('compiled', check_res, '版本信息查看失败')

        text = '-----step4:查看ssrepair帮助信息;  expect:查看成功-----'
        self.log.info(text)

        for param in self.ssrepair_list:
            check_cmd = f"source {macro.DB_ENV_PATH};dsstbox {param};"
            self.log.info(check_cmd)
            check_res = self.user_node.sh(check_cmd).result()
            self.log.info(check_res)

            self.info_res.clear()

            for line in check_res.split(' '):
                self.info_res.append(line)
            self.log.info(self.info_res)
            self.assertEqual(176, len(self.info_res), '帮助信息查看失败')

    def tearDown(self):
        self.log.info('-----No need to clean-----')
        self.log.info(f'----{os.path.basename(__file__)} end----')
